//公共依赖的模块,如果共有模块中没有需要的模块, 可在子页调用corpApp之前,手动往reliers中push   by:caochc
window.reliers = ['upApp.common', 'ui.bootstrap', 'ngSanitize', 'ngCookies', 'kendo.directives', 'angularFileUpload'];
window.corpApp = angular.module('app', reliers).run(function($rootScope){
	$rootScope.getUrl = function(item){
		return $path$ + "/admin/" + item.MenuEntranceID;
    }
}).config(['$cookiesProvider', function($cookiesProvider){}]);

corpApp.controller("MenuCtrl", ["$scope", "upserve", '$interval', '$cookies', function ($scope, upserve, $interval, $cookies) {
	$scope.menuEntranceID = angular.element("#menuEntranceID").val();
	$scope.currentMenu = {};
	$scope.ativeMenu = function(item){
		if($scope.currentMenu.isActive!=null){
			$scope.currentMenu.isActive = false;
		}
		$scope.currentMenu = item;
		$scope.currentMenu.isActive = true;
		$scope.isIndex = false;
	}
	
	//定义菜单
	var menus = new Array();
	var menu0 = [{
            "FunctionName":"计划管理",
            "isOpen":true,
            "isActive":false,
            "MenuEntranceID":"",
            "subMenu":[
                {
                    "FunctionName":"计划录入",
                    "isOpen":true,
                    "isActive":false,
                    "MenuEntranceID":"JN_PlanningInput"
                },
                {
                    "FunctionName":"计划下发",
                    "isOpen":true,
                    "isActive":false,
                    "MenuEntranceID":"JN_PlanningSend"
                },
                {
                    "FunctionName":"执行情况录入",
                    "isOpen":true,
                    "isActive":false,
                    "MenuEntranceID":"JN_PlanningExecution"
                },
                {
                    "FunctionName":"执行情况管理",
                    "isOpen":true,
                    "isActive":false,
                    "MenuEntranceID":"JN_PlanningManager"
                }
            ]
        }];
	var menu1 = [{
            "FunctionName":"预算管理",
            "isOpen":true,
            "isActive":false,
            "MenuEntranceID":"",
            "subMenu":[
                {
                    "FunctionName":"预算录入",
                    "isOpen":true,
                    "isActive":false,
                    "MenuEntranceID":"JN_BudgetInput"
                },
                {
                    "FunctionName":"预算下发",
                    "isOpen":true,
                    "isActive":false,
                    "MenuEntranceID":"JN_BudgetSend"
                },
                {
                    "FunctionName":"执行情况录入",
                    "isOpen":true,
                    "isActive":false,
                    "MenuEntranceID":"JN_BudgetExecution"
                },
                {
                    "FunctionName":"执行情况管理",
                    "isOpen":true,
                    "isActive":false,
                    "MenuEntranceID":"JN_BudgetManager"
                }
            ]
        }];
	var menu2 = [{
            "FunctionName":"统计查询",
            "isOpen":true,
            "isActive":false,
            "MenuEntranceID":"",
            "subMenu":[
                {
                    "FunctionName":"计划相关统计查询",
                    "isOpen":true,
                    "isActive":false,
                    "MenuEntranceID":"JN_PlanningStatistic"
                },
                {
                    "FunctionName":"预算相关统计查询",
                    "isOpen":true,
                    "isActive":false,
                    "MenuEntranceID":"JN_BudgetStatistic"
                },
                {
                    "FunctionName":"年度统计",
                    "isOpen":true,
                    "isActive":false,
                    "MenuEntranceID":"JN_YearStatistic"
                }
            ]
        }];
	menus.push(menu0);
	menus.push(menu1);
	menus.push(menu2);
	//获取菜单
    var getMenuList = function(){
    	if(menuId==undefined){
    		menuId = 0;
    	}
    	$scope.menuList= menus[menuId];
    };
    
    $scope.toggleMenu = function(item){
    	item.isOpen = !item.isOpen;
    	$cookies.put(item.FunctionIndex, item.isOpen);
    }
    
    getMenuList();
    
    if(menuId==='0'){
		$scope.index = $path$ + '/admin/one';
	}else if(menuId==='1'){
		$scope.index = $path$ + '/admin/two';
	}else{
		$scope.index = $path$ + '/admin/three';
	}
    
    
    var a = $interval(function(){
    	upserve.get({url:$path$ + '/checkLogin'});
    }, 1000*60*1);
}]);

corpApp.controller('navController',  ["$scope", "upserve", "ngDialog", function($scope, upserve, ngDialog){
	
	$scope.showModifyPwdDlg = function(){
		ngDialog.open({
			templateUrl: 'modify_password_dialog',
			width:500,
			controller:['$scope', 'upserve', function($scope, upserve){
				
				$scope.item = {
						Password : '',
						VerifyPassword:'',
						ConfirmPassword:''
				};
				
				$scope.close = function(){
					ngDialog.close();
				}
				
				$scope.modify = function(data){
					if($scope.item.VerifyPassword.trim()==''){
						upserve.tip('请输入原始密码', window.showTime);
						return;
					}
					if($scope.item.Password.trim()==''){
						upserve.tip('请输入新密码', window.showTime);
						return;
					}
					if($scope.item.Password.length<6){
						upserve.tip('新密码不能少于6个字符', window.showTime);
						return;
					}
					if($scope.item.Password.length>50){
						upserve.tip('新密码不能多于50个字符', window.showTime);
						return;
					}
					if($scope.item.Password!=$scope.item.ConfirmPassword){
						upserve.tip('确认密码与新密码不匹配', window.showTime)
						return ;
					}
					var data = {data:JSON.stringify($scope.item)};
					upserve.post($path$+'/admin/JN_VendorUser_UpdateUserPassword', data, function(data){
						upserve.tip('密码修改成功', window.showTime, function(){
							ngDialog.close();
						});
					});
				}
			}]
		})
	}
}]);
